package org.wkg.lesson02;

public class Demo_207 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello thread....");
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("休眠被中断");
                    // 处理中断逻辑
                    break;
                }
            }
            System.out.println("线程退出....");
        });
        System.out.println(thread.getName() + " :isAlive: " + thread.isAlive());
        thread.start();
        System.out.println(thread.getName() + " :isAlive: " + thread.isAlive());
        Thread.sleep(1000);

        thread.interrupt();
        Thread.sleep(1000);
        System.out.println(thread.getName() + " :isAlive: " + thread.isAlive());

    }
}
